/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package technotheist.imgcog.util;

import java.util.Random;

/**
 * This project is the intellectual property and only to be used under license 
 * guidelines. Please see the containing license.txt file for license information
 * and availability of use. The author takes no responsibility for any damage
 * or non-functionality caused by use of this software.
 *
 * For use of any content with a different license, please contact the author.
 * 
 * @author Mitchel Strachan <technotheist@gmail.com>
 */
public class WeightGenerator {
    public static final WeightGenerator Uniform = new WeightGenerator(1, false, false);
    public static final WeightGenerator UniformBipolar = new WeightGenerator(1, false, true);
    public static final WeightGenerator Gaussian = new WeightGenerator(1, true, false);
    public static final WeightGenerator GaussianBipolar = new WeightGenerator(1, true, true);
    
    private static final Random rand = new Random();
    //
    private float max;
    private boolean gaussian, bipolar;

    public WeightGenerator(float max, boolean gaussian, boolean bipolar) {
        this.max = max;
        this.gaussian = gaussian;
        this.bipolar = bipolar;
    }
    
    public float getRandWeight() {
        float x = rand.nextFloat();
        if(bipolar) {
            x = 2 * x - 1f;
        }
        if(gaussian) {
            x = x*x*x;
        }
        return x * max;
    }
    
    public void fillArray(float[] w) {
        for(int i = 0; i < w.length; i++) {
            w[i] = getRandWeight();
        }
    }
}
